package com.ruoyi.team.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.ruoyi.team.domain.GoodsCategory;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.List;
import java.util.stream.Collectors;

@Getter
@Setter
@ToString
public class GoodsCategoryTreeSelect {

    /** 节点ID */
    private Long id;

    /** 节点名称 */
    private String label;

    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<GoodsCategoryTreeSelect> children;

    public GoodsCategoryTreeSelect() {    }

    public GoodsCategoryTreeSelect(GoodsCategory goodsCategory) {
        this.id = goodsCategory.getId();
        this.label = goodsCategory.getCategoryName();
        this.children = goodsCategory.getChildren().stream().map(GoodsCategoryTreeSelect::new).collect(Collectors.toList());
    }
}
